package ligne2vie.topos.client.panels;

import ligne2vie.topos.client.maps.MyMapWidget;
import ligne2vie.topos.client.maps.events.MapEvent;
import ligne2vie.topos.client.maps.events.MapObserver;
import ligne2vie.topos.client.maps.events.MapPointsDisplayEvent;
import ligne2vie.topos.client.panels.search.SearchSummitsNearPosition;

import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * The class {@link SearchPanel} models the tab, displayed in the {@link ControlPanel}, dedicated to element search.
 * 
 * @author thuguerre
 * @since 1.0.0
 */
public class SearchPanel extends VerticalPanel implements MapObserver {

	/**
	 * Panel allowing to sum up georequest results.
	 */
	private GeoSearchResultDisplayPanel searchResultDisplayPanel = new GeoSearchResultDisplayPanel();

	/**
	 * Panel allowing to geo-requests summits near a position.
	 */
	private SearchSummitsNearPosition searchSummitsNearPosition = new SearchSummitsNearPosition();
	
	/**
	 * Default constructor.
	 */
	public SearchPanel() {

		// --- adding inner panels

		this.add(searchSummitsNearPosition);
		this.add(searchResultDisplayPanel);

		// --- listening to map event

		MyMapWidget.getInstance().addObserver(this);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void notifyMapEvent(MapEvent event) {

		if (event instanceof MapPointsDisplayEvent) {
			searchResultDisplayPanel.displayPoints(((MapPointsDisplayEvent) event).getPoints());
		}
	}
}
